#include "ScriptContent.h"
#include "ScriptRuntime/Type/FieldValuesContainer.h"
#include "ScriptRuntime/Type/GSharpClass.h"
#include "ScriptRuntime/Type/GSharpFieldProperty.h"

#include "Reflection/NativeClass.h"
#include "Reflection/PropertyList.h"


CScriptContent::CScriptContent(CGSharpClass *InClass)
{
    Class = InClass;

    //init attributes
    TVector<CGSharpFieldProperty*> NonStaticFields;

    for(auto Property : Class->Properties->GetNonStaticFieldProperties())
    {
        if(!Property->IsScript())
        {
            continue;
        }

        CGSharpFieldProperty *ScriptField = reinterpret_cast<CGSharpFieldProperty*>(Property);
        NonStaticFields.Add(ScriptField);
    }
    //NonStaticFields.Reverse();

    FieldValues=new CGSharpFieldValuesContainer(
        NonStaticFields
        ,InClass->GetParentNativeClass()->Properties->GetNonStaticFieldProperties().Num()
        );
}

void CScriptContent::SetNonStaticField(uint32_t FieldIndex, CAny && InValue)
{
    FieldValues->SetValue(FieldIndex,std::forward<CAny>(InValue));
}

const CAny& CScriptContent::GetNonStaticField(uint32_t FieldIndex)
{
    return FieldValues->GetValue(FieldIndex);
}

CGSharpClass *CScriptContent::GetClass() const
{
    return Class;
}

CGSharpFieldValuesContainer *CScriptContent::GetNonStaticFieldValues() const
{
    return FieldValues;
}
